
TRIGGER PROCEDURE FOR WRITE OF grd_det OLD BUFFER OLD_GRD_DET.


{mfdeclre.i }
define new shared work-table wf_old_grd_det like grd_det.

/* fdn 2004/10/28 Modify Record processing */
HK:
do:
    if can-find(first dt_mstr where dt_table = "grd_det" and dt_type = "SYNC") then
        run CreateSyncFlag(input "MOD", input recid(grd_det), input "grd_det").

    if not can-find ( first dt_mstr where dt_table = "grd_det" and dt_type = "MOD" ) then leave HK.
    
    if not can-find ( first wf_old_grd_det ) then do:
        create wf_old_grd_det.
        if recid(wf_old_grd_det)= -1 then .
    end.
    
    buffer-copy OLD_GRD_DET to wf_old_grd_det no-error.

    for each dt_mstr no-lock where dt_table = "grd_det" and dt_type = "MOD" :
    
        case dt_field :

            when "grd_id" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_id, input grd_det.grd_id,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_group" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_group), input string(grd_det.grd_group),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_number" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_number), input string(grd_det.grd_number),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_part" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_part, input grd_det.grd_part,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_sub_part" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_sub_part, input grd_det.grd_sub_part,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_type" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_type, input grd_det.grd_type,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_status" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_status, input grd_det.grd_status,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_pm_code" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_pm_code, input grd_det.grd_pm_code,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_site" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_site, input grd_det.grd_site,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_req_site" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_req_site, input grd_det.grd_req_site,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_buyer" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_buyer, input grd_det.grd_buyer,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_req_buyer" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_req_buyer, input grd_det.grd_req_buyer,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_vend" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_vend, input grd_det.grd_vend,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_price" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_price), input string(grd_det.grd_price),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_rel_date" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_rel_date), input string(grd_det.grd_rel_date),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_due_date" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_due_date), input string(grd_det.grd_due_date),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_qty_req" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_qty_req), input string(grd_det.grd_qty_req),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_qty_avail" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_qty_avail), input string(grd_det.grd_qty_avail),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_qty_stk" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_qty_stk), input string(grd_det.grd_qty_stk),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_qty_pod" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_qty_pod), input string(grd_det.grd_qty_pod),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_qty_demand" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_qty_demand), input string(grd_det.grd_qty_demand),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_all_pct" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_all_pct), input string(grd_det.grd_all_pct),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_all_pre" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_all_pre), input string(grd_det.grd_all_pre),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_all_eff" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_all_eff), input string(grd_det.grd_all_eff),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_qty_phantom" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_qty_phantom), input string(grd_det.grd_qty_phantom),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_sfty_stk" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd_sfty_stk), input string(grd_det.grd_sfty_stk),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_rsn_code" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_rsn_code, input grd_det.grd_rsn_code,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_reason" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_reason, input grd_det.grd_reason,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_rmks" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_rmks, input grd_det.grd_rmks,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd_curr" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd_curr, input grd_det.grd_curr,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__chr01" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd__chr01, input grd_det.grd__chr01,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__chr02" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd__chr02, input grd_det.grd__chr02,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__chr03" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd__chr03, input grd_det.grd__chr03,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__chr04" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input wf_old_grd_det.grd__chr04, input grd_det.grd__chr04,
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__dec01" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__dec01), input string(grd_det.grd__dec01),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__dec02" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__dec02), input string(grd_det.grd__dec02),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__dec03" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__dec03), input string(grd_det.grd__dec03),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__dec04" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__dec04), input string(grd_det.grd__dec04),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__int01" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__int01), input string(grd_det.grd__int01),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__int02" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__int02), input string(grd_det.grd__int02),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__dte01" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__dte01), input string(grd_det.grd__dte01),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__dte02" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__dte02), input string(grd_det.grd__dte02),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__log01" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__log01), input string(grd_det.grd__log01),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").

            when "grd__log02" then
                run CreateDthist(input dt_table, input dt_field, input dt_type, input string(wf_old_grd_det.grd__log02), input string(grd_det.grd__log02),
                    input recid(grd_det), input grd_det.grd_id, input string(grd_det.grd_group), input string(grd_det.grd_number), input grd_det.grd_part,
                    input grd_det.grd_sub_part, input "", input "", input "").
        end.
        
    end.
end.

{hkdttrans.i}
